// PersistentFacadeImp.cpp: implementation of the PersistentFacadeImp class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PersistentFacadeImp.h"
#include "RecordsetPtrWrap.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

using namespace DAWrapper;
PersistentFacadeImp::~PersistentFacadeImp()
{
	for ( int i = 0; i < m_CatalogItems.GetSize(); i++ )
		delete m_CatalogItems.GetAt( i );
}

_ConnectionPtr* PersistentFacadeImp::GetPCMConnection()
{
	if ( m_PCMConn ) return m_PCMConn;
	m_PCMConn = DBConnectionManager::Instance()->GetConnectionPtrByUri( _T( "PCM.mdb" ) );
	return m_PCMConn;
}

_ConnectionPtr* PersistentFacadeImp::GetProductCatalogConnection( const CString& pcid )
{
	for ( int i = 0; i < m_CatalogItems.GetSize(); i++ )
		if ( m_CatalogItems.GetAt( i )->ID() == pcid )
			return m_CatalogItems.GetAt( i )->DataSourceConnection();
	return 0;
}

JointRegularSet* PersistentFacadeImp::GetJointRegularSet()
{
	JointRegularSet* pSet = this->m_JointRegularSet.Generate();
	ASSERT(pSet);
	return pSet;
}

PartParameterFormerSet* PersistentFacadeImp::GetPartParameterFormerSet()
{
	PartParameterFormerSet* pSet = this->m_ParameterFormerSet.Generate();
	ASSERT(pSet);
	return pSet;
}

void PersistentFacadeImp::CloseConnection()
{
	DBConnectionManager::Instance()->DeleteInstance();
}

PartCrudeDataSet* PersistentFacadeImp::GetPartCrudeDataSet()
{
	PartCrudeDataSet* pSet = this->m_PartCrudeDataSet.Generate();
	ASSERT(pSet);
	return pSet;
}

CurPartSet* PersistentFacadeImp::GetCurPartSet()
{
	CurPartSet* pSet = this->m_CurPartSet.Generate();
	ASSERT(pSet);
	return pSet;
}

SpringSet* PersistentFacadeImp::GetSpringSet()
{
	SpringSet* pSet = this->m_SpringSet.Generate();
	ASSERT(pSet);
	return pSet;
}

StandardGenerator* PersistentFacadeImp::GetStandardGenerator()
{
	return &m_StandardSet;
}

ConstSpringDisSerialManager* PersistentFacadeImp::GetConstSpringDisSerialManager()
{
	return &m_CSpringDisSerialManager;
}

ConstSpringSet* PersistentFacadeImp::GetConstSpringSet()
{
	return &m_CSpringSet;
}

ConstSpringJointPortSet* PersistentFacadeImp::GetConstSpringJointPortSet()
{
	return &m_CSpringJointPortSet;
}